<?php #Корзина
/* if(empty($_POST))
	$_POST=$_GET;
	$elog=false;
	$conn->echoQ=true; */
	
	$basket_id = getBasketId();
	
	$action			= isset( $_POST['action'] ) 		? $_POST['action']			: '';
	$pr_code		= isset( $_POST['product_code'] )	? $_POST['product_code']	: 0;
	$delivery_type	= isset( $_POST['delivery_type'] )	? $_POST['delivery_type']	: 'self';
	
	switch ( $action )
	{
		case 'show_cart':
			echo $load->block('basket');
			exit;
		case 'delete_cart_product':
				$conn->query( 'DELETE FROM `store_basket_products` WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$pr_code );
				$pr_code = 0;
			break;
		case 'switch_services':
			if( $_POST['check'] )
			{
				$set = '`inst` = 1'.( $_POST['service'] == 'vip' ? ', `vip` = 1' : '' );
				$set .= ', `count_inst` = IF(`count_inst` = 0, `count`, `count_inst` )'.( $_POST['service'] == 'vip' ? ', `count_vip` = IF(`count_vip` = 0, `count`, `count_vip` )' : '' );
			}
			else
				$set = '`vip` = 0'.( $_POST['service'] == 'inst' ? ', `inst` = 0' : '' );
			
			$conn->query( 'UPDATE `store_basket_products` SET '.$set.' WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$pr_code );
			break;
		case 'update_count_pr':
			$count = $_POST['count'];
			if( $count > 0 )
			{
				$conn->query('SELECT `count`, `inst`, `vip`, `count_inst`, `count_vip` FROM `store_basket_products` WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$pr_code );
				$row = $conn->fetch();

				$conn->query('UPDATE `store_basket_products` SET `count` = '.$count.' WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$pr_code);
				if( $row->inst )
					$conn->query('UPDATE `store_basket_products` SET `count_inst` = '.$count.' WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$pr_code );
				if( $row->vip )
					$conn->query('UPDATE `store_basket_products` SET `count_vip` = '.$count.' WHERE `basket_id` = '.$basket_id.' AND `product_code` = '.$pr_code );
			}
			break;
	}

	$counts = getCountProduct( $basket_id, $pr_code );
	$costs = getTotalCosts( $basket_id, $delivery_type, $pr_code );
	displayMessage( $counts , $costs );	

